//
//  NavBar.cpp
//  PlantNanny
//
//  Created by Joueu on 14-12-24.
//
//

#include "NavBar.h"
#include "Resource.h"

bool NavBar::init()
{
    if (!Sprite::initWithFile("nav_bar@2x.png")) {
        return false;
    }
    
    header = Label::createWithSystemFont("状 态", "微软雅黑", 40);
    header -> setPosition(this -> getContentSize() * 0.5f);
    header -> setTextColor(Color4B(200, 200, 200,255));
    header -> enableShadow();
    this -> addChild(header);
    
    ui::Button *returnBtn = ui::Button::create("navi_back@2x.png");
    returnBtn -> setPosition(Point(this -> getContentSize().width * 0.08f, this -> getContentSize().height * 0.5f));
    returnBtn -> addTouchEventListener(CC_CALLBACK_2(NavBar::returnBtnPressed, this));
    this -> addChild(returnBtn);
    
    return true;
}


void NavBar::returnBtnPressed(Ref *pSender, ui::Button::TouchEventType type)
{
    if (type == ui::Button::TouchEventType::ENDED) {
        PlayNegativeSound;
        Scene *preScene = Director::getInstance() -> getPreviousScene();
        TransitionScene *transition = TransitionSlideInR::create(0.3, preScene);
        Director::getInstance() -> popSceneWithTransition(transition);
    }
}


void NavBar::setHeaderName(const std::string &name)
{
    header -> setString(name);
}